package org.sherlock.plugins.revealers;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.sherlock.commons.model.RemoteFile;
import org.sherlock.commons.model.RemoteMusicFile;
import org.sherlock.commons.plugins.RevealerException;
import org.sherlock.commons.plugins.URLRevealer;

/**
 *
 * @author Sherlock Downloader
 */
public class Revealer extends URLRevealer {

    @Override
    public ArrayList<RemoteFile> getURLs(URL url) throws RevealerException {
        ArrayList<RemoteFile> files = new ArrayList<RemoteFile>();
        try {
            URL newURL = new URL("http://www.goear.com/tracker758.php?f=" + url.toString().split("/")[4]);
            String xml = getContent(newURL.openStream(), Charset.defaultCharset());
            String remoteFile = xml.split("song path=\"")[1].split("\"")[0];
            String artist = xml.split("artist=\"")[1].split("\"")[0];
            String title = xml.split("title=\"")[1].split("\"/")[0];
            files.add(new RemoteMusicFile(artist, "Unknown", title, new URI(remoteFile)));
        } catch (IOException ex) {
            Logger.getLogger(Revealer.class.getName()).log(Level.SEVERE, null, ex);
		} catch (URISyntaxException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return files;
    }
}
